package com.besttone.search.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import com.besttone.search.model.City;
import com.besttone.search.model.PhoneInfo;

public class SharedUtils {
	public static final String Custom_Channel = "custom_channel";
	public static final String Data_Selected_City = "Data_Selected_City";
	public static final String First_Selected_City = "First_Selected_City";
	public static final String Location_AreaCode = "Location_AreaCode";
	public static final String Location_City = "Location_City";
	public static final String Location_CityCode = "Location_CityCode";
	public static final String Location_CityId = "Location_CityId";
	public static final String Location_ProvinceCode = "Location_ProvinceCode";
	public static final String NOTIFICATION_SET = "notification_set";
	public static final String SHORT_CUT_INSTALLED = "short_cut_installed";
	public static final String Switch_City_Notice = "Switch_City_Notice";
	public static final String Total_Channel = "total_channel";
	public static SharedPreferences mPreference;

	public static String getCurrentCityCode(Context paramContext) {
		return getPreference(paramContext).getString("Location_CityCode", "");
	}

	public static String getCurrentCityId(Context paramContext) {
		return getPreference(paramContext).getString("Location_CityId", "");
	}

	public static String getCurrentCityName(Context paramContext) {
		return getPreference(paramContext).getString("Location_City", "");
	}

	public static String getCurrentProvinceCode(Context paramContext) {
		return getPreference(paramContext).getString("Location_ProvinceCode",
				"");
	}
	
	public static String getCurrentSimplifyCode(Context paramContext) {
		return getPreference(paramContext).getString("Location_SimplifyCode", "");
	}

	public static long getNotificationHistory(Context paramContext,
			String paramString) {
		return getPreference(paramContext).getLong(paramString, 0L);
	}

	public static int getNotificationSet(Context paramContext) {
		return getPreference(paramContext).getInt("notification_set", 0);
	}

	public static SharedPreferences getPreference(Context paramContext) {
		if (mPreference == null)
			mPreference = PreferenceManager
					.getDefaultSharedPreferences(paramContext);
		return mPreference;
	}

	public static String getUseVersion(Context paramContext) {
		return getPreference(paramContext).getString("USE_VERSION", "");
	}

	public static String getVersionChannelList(Context paramContext) {
		String str1 = getUseVersion(paramContext);
		String str2 = getPreference(paramContext).getString(
				"CHANNEL_VERSION_" + str1, "");
		LogUtils.d("getCityChannelList: CHANNEL_VERSION_" + str1 + ", " + str2);
		return str2;
	}

	public static boolean hasShowHelp(Context paramContext) {
		return getPreference(paramContext).getBoolean("SHOW_HELP", false);
	}

	public static boolean isFirstSelectedCityComplete(Context paramContext) {
		return getPreference(paramContext).getBoolean("First_Selected_City",
				false);
	}

	public static boolean isShortCutInstalled(Context paramContext) {
		return getPreference(paramContext).getBoolean("short_cut_installed",
				false);
	}

	public static boolean isShowSwitchCityNotice(Context paramContext) {
		return getPreference(paramContext).getBoolean("Switch_City_Notice",
				true);
	}

	public static void setCurrentCity(Context paramContext, City paramCity) {
		SharedPreferences.Editor localEditor = getPreference(paramContext)
				.edit();
		localEditor.putString("Location_City", paramCity.getCityName());
		localEditor.putString("Location_CityCode", paramCity.getCityCode());
		localEditor.putString("Location_CityId", paramCity.getCityId());
		localEditor.putString("Location_ProvinceCode",
				paramCity.getProvinceCode());
		localEditor.putString("Location_AreaCode", paramCity.getAreaCode());
		localEditor.putString("Location_SimplifyCode", paramCity.getSimplifyCode());
		LogUtils.d("setCurrentCity================");
		LogUtils.d("cityCode:" + paramCity.getCityCode());
		LogUtils.d("cityName:" + paramCity.getCityName());
		LogUtils.d("areaCode:" + paramCity.getAreaCode());
		LogUtils.d("SimplifyCode:" + paramCity.getSimplifyCode());
		localEditor.commit();
	}

	public static void setFirstSelectedCityComplete(Context paramContext) {
		getPreference(paramContext).edit()
				.putBoolean("First_Selected_City", true).commit();
	}

	public static void setNotificationHistory(Context paramContext,
			String paramString, long paramLong) {
		if (!TextUtils.isEmpty(paramString)) {
			getPreference(paramContext).edit().putLong(paramString, paramLong)
					.commit();
			LogUtils.d("SET:" + paramString + " ," + paramLong);
		}
	}

	public static void setNotificationSet(Context paramContext, int paramInt) {
		getPreference(paramContext).edit().putInt("notification_set", paramInt)
				.commit();
	}

	public static void setShortCutInstalled(Context paramContext) {
		getPreference(paramContext).edit()
				.putBoolean("short_cut_installed", true).commit();
	}

	public static void setShowHelp(Context paramContext) {
		getPreference(paramContext).edit().putBoolean("SHOW_HELP", true)
				.commit();
	}

	public static void setSwitchCityNotice(Context paramContext,
			boolean paramBoolean) {
		getPreference(paramContext).edit()
				.putBoolean("Switch_City_Notice", paramBoolean).commit();
	}

	public static void setUseVersion(Context paramContext, String paramString) {
		getPreference(paramContext).edit()
				.putString("USE_VERSION", paramString).commit();
		LogUtils.d("setUseVersion: " + paramString);
	}

	public static void setVersionChannelList(Context paramContext,
			String paramString1, String paramString2) {
		getPreference(paramContext).edit()
				.putString("CHANNEL_VERSION_" + paramString1, paramString2)
				.commit();
		LogUtils.d("setCityChannelList: CHANNEL_VERSION_" + paramString1 + ", "
				+ paramString2);
	}

	public static boolean versionListExist(Context paramContext,
			String paramString) {
		if (getPreference(paramContext).contains(
				"CHANNEL_VERSION_" + paramString))
			LogUtils.d("Version:" + paramString + "Exist!");
		return true;
	}
	
	public static void setCurrentPhoneInfo(Context paramContext, PhoneInfo info) {
		SharedPreferences.Editor localEditor = getPreference(paramContext)
				.edit();
		localEditor.putString("Phone_DeviceId", info.getImei());
		localEditor.putString("Phone_Imsi", info.getImsi());
		localEditor.putString("Phone_No", info.getPhoneNo());
		localEditor.putString("Phone_Provider", info.getProvider());
		localEditor.commit();
	}
	
	public static String getCurrentPhoneDeviceId(Context paramContext) {
		return getPreference(paramContext).getString("Phone_DeviceId", "");
	}
	
	public static String getCurrentPhoneImsi(Context paramContext) {
		return getPreference(paramContext).getString("Phone_Imsi", "");
	}
	
	public static String getCurrentPhoneNo(Context paramContext) {
		return getPreference(paramContext).getString("Phone_No", "");
	}
	
	public static String getCurrentPhoneProvider(Context paramContext) {
		return getPreference(paramContext).getString("Phone_Provider", "");
	}
}